// packageA/pages/my-redpacket/my-redpacket.js
import {RedPacket} from '../../../models/redpacket'
import {check} from '../../../util/identityCheck'
import Dialog from '../../../miniprogram_npm/@vant/weapp/dialog/dialog'


let packetModel = new RedPacket()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    rule: '',
    packet: {}
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if(!check())return
    this.getPacketRule()
    this.getMyPacket()
  },

  getPacketRule () {
    packetModel.getPacketRule(res => {
      this.setData({
        rule: res.rule
      })
    })
  },

  getMyPacket () {
    packetModel.getMyPacket(res => {
      this.setData({
        packet: res
      })
    })
  },

  takeMoney() {
    Dialog.alert({
      title: '提示',
      message: '立即前往查看招聘，赢取现金红包奖励！',
      confirmButtonText: '去看看',
      cancelButtonText: '去提现',
      showCancelButton: true
    }).then(() => {
      wx.switchTab({
        url: `/pages/recruit/recruit`
      })
    }).catch(() => {
      wx.navigateTo({
        url: `/packageA/pages/withdraw/withdraw`
      })
    })
  },

  toDetail() {
    wx.navigateTo({
      url: `/packageA/pages/redpacket-detail/redpacket-detail`
    })
  },

  toRecurit() {
    wx.switchTab({
      url: `/pages/recruit/recruit`
    })
  },

  sendNotify () {
    // 发送微信订阅消息推送 邀请下级成功通知
    wx.requestSubscribeMessage({
      tmplIds: ['kssElCTfi5u46xhxN8UusFWt2fEt6amK7SYKtbIvDuA', 'jS6-rLU0vNw70iCAfexfpDXdTyn0zIMR7BMkUqqCsJk']
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '闲买足疗人',
      imageUrl: 'https://m.xianmaiyangsheng.com/xcxImg/image/zuliaoren/redpacketshare.png',
      path: `/pages/main/main?otherId=${wx.getStorageSync('userInfo').user_id}&time=${+new Date()}`
    }
  }
})